<template>
  <CompOperate
      :field="field"
      :designer="designer"
      :design-state="designState"
      :parent-list="parentList"
      :parent-widget="parentWidget"
      :sub-form-row-id="subFormRowId"
      :sub-form-row-index="subFormRowIndex"
      :sub-form-col-index="subFormColIndex"
      :index-of-parent-list="indexOfParentList"
      :display-style="field.options.displayStyle"
  >
    <div class="scene-DRC-pass-patient-widget" :style="getStyle('head')">
      <div class="widget-inside">
        <!--科室信息-->
        <div class="dept-room" :class="{'dept-room-hide':(optionsInfo?.checkList?.length)===1}">
          <p class="dept" v-if="(optionsInfo.checkList).includes(1)" :style="getStyle('roomInfo')">
            <ScrollX>
              {{ getRoomDeptInfo[optionsInfo['deptNameKey'] || 'deptName'] || '\u00a0' }}
            </ScrollX>
          </p>
          <p class="room" v-if="(optionsInfo.checkList).includes(3)" :style="getStyle('roomInfo')">
            <ScrollX>
              {{ getRoomDeptInfo[optionsInfo['roomNameKey'] || 'roomName'] || '\u00a0' }}
            </ScrollX>
          </p>
        </div>
        <!--医生信息-->
        <div class="doctor-patient">
          <template v-for="item in getRoomDoctorInfo">
            <div class="patient-area">
              <div class="current patient" :style="getStyle('patientInfo')">
                <div class="sign">正在呼叫</div>
                <template v-for="patientItem in getPatient(item,'treatingPatient')">
                  <div class="content">
                    <div class="inside-item" :style="getStyle('currentPatientInfo')">
                      {{currentPatient(item,patientItem)}}
<!--                      {{ patientItem?.patientName || '\u00a0' }}-->
                    </div>
                  </div>
                </template>
              </div>
              <div class="wait patient" :style="getStyle('patientInfo')">
                <div class="sign">等待人员</div>
                <div class="content">
                  <template v-for="patientItem in getPatient(item,'waitingPatientList')">
                    <div class="patient-item">
                      <div class="inside-item" :style="getStyle('waitPatientInfo')">
                        {{ patientItem?.patientName || '\u00a0' }}
                      </div>
                    </div>
                  </template>
                </div>
              </div>
            </div>
          </template>
        </div>
        <!--温馨信息-->
        <div class="tips-area">
          <div class="sign" :style="getStyle('tipsSign')">温馨提示</div>
          <div class="content">
            <ScrollEditY :content="optionsInfo.tipsContent || '\u00a0'" :pageDuration="10"/>
          </div>
        </div>
      </div>

    </div>
  </CompOperate>
</template>

<script>
import {pxToVw} from '@/utils/common';
import emitter from "@/utils/designer/emitter";
import {buildParentApi} from "@/utils/designer/util";
import ScrollY from '@c/public/seamlessScroll/ScrollY.vue'
import CompOperate from "@c/public/form-designer/devType/modules/compOperate.vue";
import mixin from "@sc/templateDetails/modules/homeMiddle/fieldMixin";
import ScrollX from "@c/public/seamlessScroll/ScrollX.vue";
import ScrollEditY from "@c/public/seamlessScroll/ScrollEditY.vue";

let buildParent = buildParentApi();
export default {
  name: "scene-DRC-patient-widget",

  componentName: "FieldWidget", //必须固定为FieldWidget，用于接收父级组件的broadcast事件

  mixins: [emitter, mixin],

  components: {
    ScrollEditY,
    ScrollX,
    CompOperate,
    ScrollY
  },

  props: {
    widget: Object,
    devType: {
      type: Boolean,
      default: false,
    },
    field: Object,
    parentWidget: Object,
    parentList: Array,
    indexOfParentList: Number,
    designer: Object,
    designState: {
      type: Boolean,
      default: false,
    },
    subFormRowIndex: {
      /* 子表单组件行索引，从0开始计数 */ type: Number,
      default: -1,
    },
    subFormColIndex: {
      /* 子表单组件列索引，从0开始计数 */ type: Number,
      default: -1,
    },
    subFormRowId: {
      /* 子表单组件行Id，唯一id且不可变 */ type: String,
      default: "",
    },
    headTitle: {
      type: String,
      default: "",
    },
    visibleTitle: {
      type: Boolean,
    },
    //prop传入的表单JSON配置
    parentApi: {
      type: Object,
      default: () => buildParentApi()
    },
  },

  data() {
    return {
      states: true,
      optionsInfo: Object(),
      header: require("@a/images/design/header.jpeg"),
    }
  },

  computed: {
    // 设置的行内样式
    getStyle() {
      return function (val) {
        const self = this;
        let info = (self.optionsInfo) || Array();
        let Obj = Object();
        switch (val) {
          case 'head':
            Reflect.set(Obj, 'height', pxToVw(info.headHeight));
            Reflect.set(Obj, 'backgroundColor', `${(info.backgroundColor)}`);
            return Obj;
          case 'roomInfo':
            Reflect.set(Obj, 'color', (info.roomInfoColor));
            Reflect.set(Obj, 'fontWeight', (info.roomInfoFontWeight));
            return Obj;
          case 'doctorInfo':
            Reflect.set(Obj, 'fontWeight', (info.doctorInfoFontWeight));
            return Obj;
          case 'patientInfo':
            Reflect.set(Obj, 'fontWeight', (info.patientInfoFontWeight));
            return Obj;
          case 'currentPatientInfo':
            Reflect.set(Obj, 'fontSize', pxToVw(info.currentPatientContentFontsize));
            return Obj;
          case 'waitPatientInfo':
            Reflect.set(Obj, 'fontSize', pxToVw(info.waitPatientContentFontsize));
            return Obj;
          case 'tipsSign':
            Reflect.set(Obj, 'color', (info.tipsTitleInfoColor));
            Reflect.set(Obj, 'fontWeight', (info.tipsTitleInfoFontWeight));
            return Obj;
          case 'passPatient':
            Reflect.set(Obj, 'color', (info.passPatientInfoColor));
            Reflect.set(Obj, 'fontWeight', (info.passPatientInfoFontWeight));
            return Obj;
        }
      }
    },

    // 获取全量医患信息
    getRoomDoctorInfo() {
      let temp = Array();
      let devType = (this.devType);
      let roomDoctorInfo = this.$store.getters['getRoomDoctorInfo'];
      if (devType) {
        if (!!(roomDoctorInfo.apiData?.length)) {
          return roomDoctorInfo.apiData.slice(0, 1);
        } else {
          return temp.push({});
        }
      } else {
        if (!!(roomDoctorInfo.mockData?.length)) {
          return roomDoctorInfo.mockData.slice(0, 1);
        } else {
          return temp.push({});
        }
      }
    },

    // 获取科室信息
    getRoomDeptInfo() {
      let devType = (this.devType);
      let roomDoctorInfo = this.$store.getters['getRoomDeptInfo'];
      if (devType) {
        return roomDoctorInfo.apiData;
      } else {
        return roomDoctorInfo.mockData;
      }
    },

    //获取患者
    getPatient() {
      return function (row, key = 'treatingPatient') {
        let list = row[key] || Array();
        switch (key) {
          case 'treatingPatient':
            if (list?.length) {
              return list.slice(0, 1)
            } else {
              return new Array(1).fill({})
            }
          case 'waitingPatientList':
            if (list?.length >= 2) {
              return list.slice(0, 2)
            } else {
              let fillArr = (new Array(2 - list.length).fill({}));
              return [...list, ...fillArr];
            }
        }
      }
    },

    // 正在就诊的患者
    currentPatient() {
      return function (row,patientInfo) {
        let isPause = (row?.isPause);
        if (!isPause) {
          return (patientInfo?.patientName) || '\u00a0'
        } else {
          return '暂停接诊';
        }
      }
    }
  },

  created() {
    this.registerToRefList();
    this.initEventHandler();
    this.handleOnCreated();
  },

  mounted() {
    this.handleOnMounted();
  },

  methods: {
    // 接收父组件传递过来的数据
    executeMethod(key, data) {
      switch (key) {
        case "roomDeptInfo":
          this.$store.dispatch('setRoomDeptInfo', this.$lodash.cloneDeep(data))
          break
        case "roomDoctorInfo":
          this.$store.dispatch('setRoomDoctorInfo', this.$lodash.cloneDeep(data))
          break
      }
    },

  },

  watch: {
    field: {
      handler: function (val) {
        let key = val.options.config
        this.optionsInfo = val.options[key];
      },
      deep: true,
      immediate: true
    }
  },

  destroyed() {
    this.unregisterFromRefList();
  },

};
</script>

<style lang="scss" scoped>
.scene-DRC-pass-patient-widget {
  padding: 22px 30px 22px 30px;
  color: #333;
  font-size: 40px;
  background: transparent;
  box-sizing: border-box;
  overflow: hidden;

  .widget-inside {
    height: calc(100%);
    border-radius: 18px;
    padding: 24px 34px 24px 34px;
    box-sizing: border-box;
    overflow: hidden;
    background: rgba(0, 0, 0, 0.1);
    //科室
    .dept-room {
      background: #0059B3;
      box-sizing: border-box;
      border-radius: 20px;
      height: 232px;
      overflow: hidden;

      p {
        color: #FFFFFF;
        font-size: 90px;
        width: 100%;
        overflow: hidden;
        line-height: 1.26;
        text-align: center;
      }
    }

    .dept-room-hide {
      display: flex;
      width: 100%;
      justify-content: center;
      align-items: center;
      align-self: center;

      .room {
        font-size: 140px;
      }
    }

    //患者-医生
    .doctor-patient {
      height: calc(100% - 232px - 616px - 42px);
      margin-top: 22px;
      box-sizing: border-box;
      overflow: hidden;
      //患者信息
      .patient-area {
        border-radius: 12px;
        box-sizing: border-box;
        height: calc(100%);
        border: 1px rgba(255, 255, 255, 0) solid;

        .patient {
          display: flex;
          flex-direction: column;
          overflow: hidden;
        }

        .current {
          height: 284px;
          background: rgba(7, 82, 192, 0.5);

          .sign {
            margin: 0 108px;
            border-radius: 0 0 16px 16px;
            height: 80px;
            font-size: 60px;
            color: rgba(255, 255, 255, 1);
            text-align: center;
            line-height: 80px;
            background: #00B0FD;
          }

          .content {
            height: calc(100% - 80px);
            width: 100%;
            font-size: 90px;
            color: #ECFF24;
            padding: 0 60px;
            @include singleEllipsis(100%);

            .inside-item {
              display: flex;
              height: 100%;
              align-items: center;
              justify-content: center;
            }
          }
        }

        .wait {
          height: calc(100% - 284px);
          box-sizing: border-box;
          display: flex;
          flex-direction: column;

          .sign {
            height: 100px;
            width: 100%;
            line-height: 100px;
            text-align: center;
            margin-top: 20px;
            font-size: 60px;
            color: white;
            border-radius: 12px;
            overflow: hidden;
            box-sizing: border-box;
            background: rgba(7, 82, 192, 0.5);

            &:before {
              content: '';
              display: inline-block;
              width: 60px;
              height: 56px;
              overflow: hidden;
              margin-right: 18px;
              @include background('design/bg7-1×2');
              background-size: contain;
              background-position: 10px;
              position: relative;
              top: 2px;
            }
          }

          .content {
            margin-top: 20px;
            padding: 40px 160px;
            border-radius: 12px;
            overflow: hidden;
            box-sizing: border-box;
            height: calc(100% - 100px);
            background: rgba(7, 82, 192, 0.5);
          }

          .patient-item {
            width: 100%;
            height: calc((100% - 16px) / 2);
            text-align: center;
            font-size: 90px;
            color: #ECFF24;
            display: flex;
            align-items: center;
            justify-content: center;
            white-space: nowrap;
            border-radius: 16px;
            overflow: hidden;
            @include singleEllipsis(100%);
            background: rgba(0, 64, 170, 1);

            .inside-item {
              display: flex;
              height: 100%;
              align-items: center;
              justify-content: center;
            }

            &:last-child {
              margin-top: 16px;
            }
          }
        }
      }
    }

    // 温馨提示
    .tips-area {
      height: 616px;
      margin-top: 14px;
      overflow: hidden;
      box-sizing: border-box;
      border-radius: 12px;
      background: rgba(7, 82, 192, 0.5);

      .sign {
        height: 88px;
        padding: 0 20px;
        text-align: center;
        display: flex;
        align-self: center;
        align-content: center;
        align-items: center;
        justify-content: center;
        border-bottom: 1px rgba(255, 255, 255, 0.5) solid;
        font-weight: 500;
        overflow: hidden;
        font-size: 54px;
        line-height: 1.4;
        color: #ECFF24;
        box-sizing: border-box;
      }

      .content {
        padding: 10px 20px 0 20px;
        margin: 24px 0;
        font-size: 50px;
        box-sizing: border-box;
        overflow: hidden;
        //color: rgba(255, 255, 255, 1);
        line-height: 1.8;
        height: calc(100% - 88px - 48px);
      }
    }
  }

}
</style>
